<?php include view_path().'header_total.php';?>
<head>
<link rel="stylesheet" type="text/css" href="<?php echo css_url().'960grid/960.css'?>">
<link rel="stylesheet" type="text/css" href="<?php echo css_url().'960grid/960_extra.css'?>">
<link rel="stylesheet" type="text/css" href="<?php echo css_url().'960grid/960_table.css'?>">
<link rel="stylesheet" type="text/css" href="<?php echo css_url().'button.css'?>">
</head>

<section id='body'>
    <div class="tab-titles">
        <div class="container_12">
            <div class="grid_1">&nbsp;</div>
            <a href='<?php echo site_url().'/user_group2/applicants'?>'>
                <div id="pending-tab" class="grid_3 tab-entities" clicked>
                    Find Applicants
                </div>
            </a>
            <a href='<?php echo site_url().'/user_group2/applicants/favorite'?>'>
                <div id="accept-tab" class="grid_3 tab-entities">
                    Favorite Applicants
                </div>
            </a>
        </div>
    </div>
    
    <div id="applicants-content-area">
        
        <div class="container_12 header">
            <div class='grid_1'>&nbsp;</div>
            <div class='grid_2'>Name</div>
            <div class='grid_2'>Sex</div>
            <div class='grid_2'>Age</div>
            <div class='grid_2'>Email</div>
        </div>
    <?php foreach($Applicants as $App): ?>
        <div class="container_12 row">
            <div class='grid_1 text-center'>
                <div class="add-favorite-btn<?php
                    if($App['IsFavorite'])
                        echo "-clicked";
                ?>" appid='<?php echo $App['UserGroup3ID']?>'> &nbsp; &nbsp; &nbsp; </div>
            </div>
            <a href='<?php echo site_url().'/user_group3/'.$App['UserGroup3ID']?>'>
            <div class="grid_2">
                <?php echo $App['UserFullname']?>
            </div>
            <div class="grid_2 text-center">
                <?php echo $App['Sex']?>
            </div>
            <div class="grid_2 text-center">
                <?php echo $App['Age']?>
            </div>
            <div class="grid_2">
                <?php echo $App['RelUserEmail']?>
            </div>
            </a>
            <div class="hide-in-row">
                    <div class="content" style="background-image: url('<?php echo $App['AvatarLink']?>');">
        <!--                <image src="" style="float:left"></image>-->
                        <?php 
                        if($App['Describtion']){
                            echo $App['Describtion']; 
                        }else{
                            echo "No describtion about himself/herself";
                        }
                        ?>
                    </div>
            </div>
        </div>
    <?php endforeach; ?>
    </div>
</section>

<script>
    $(document).ready(function(){
        var addfavorite = function (){
            $('.add-favorite-btn').unbind('click');
            $('.add-favorite-btn').on('click', function (e) {
                var UserGroup3ID = $(this).attr("appid");
                $.ajax({
                        url : '<?php echo site_url().'/user_group2/applicants/add_favorite'?>',
                        type: 'POST',
                        data: { UserGroup3ID : UserGroup3ID},
                        async: false,
                        success: function(data){
                            result = data;
                        }
                });
                if(result == 1 || result == "1"){
                    $(this).attr('class', 'add-favorite-btn-clicked');
                    removefavorite();
                }
                else{
                    alert("Can not add to favrite");
                }
            });
        }

        var removefavorite = function(){
            $('.add-favorite-btn-clicked').unbind('click');
            $('.add-favorite-btn-clicked').on('click', function (e) {
                var UserGroup3ID = $(this).attr("appid");
                result = "0";
                $.ajax({
                        url : '<?php echo site_url().'/user_group2/applicants/remove_favorite'?>',
                        type: 'POST',
                        data: { UserGroup3ID : UserGroup3ID},
                        async: false,
                        success: function(data){
                            result = data;
                        }
                });
                if(result == 1 || result == "1"){
                    $(this).attr('class', 'add-favorite-btn');
                    addfavorite();
                }
                else{
                    alert("Can not remove from favrite");
                }
            });
        }

        addfavorite();
        removefavorite();
    });
</script>
<?php include view_path().'footer.php';?>
